<?php
class app_install extends app implements interface_app {

    public function pre_dispatch(){

        // Upgrade
        $upgrade = false;

        if (file_exists($this->load->get_path('dir_root') . 'config.php')) {
            if (filesize($this->load->get_path('dir_root') . 'config.php') > 0) {
                $upgrade = true;

                $lines = file($this->load->get_path('dir_root') . 'config.php');

                foreach ($lines as $line) {
                    if (strpos(strtoupper($line), 'DB_') !== false) {
                        eval($line);
                    }
                }
            }
        }


        // Router
        if (isset($this->request->get['route'])) {
            $this->action = $this->action($this->request->get['route']);
        } elseif ($upgrade) {
            $this->action =  $this->action('upgrade');
        } else { 
            $this->action = $this->action('step_1');
        }

        // Set http url to installer
        $this->url->setURL(HTTP_INSTALL);
    }
}
